The third method of TemplateField is to display the metadata of data in the GridView. For example, in addition to displaying the employee's employment date, we may also want to use a column to show how long the employee has been working in the company.
There is also a usage that will be used in some cases. For example, the display format of a data on the page needs to be different from the storage format in
C # example
Using System; using System. data; using System. configuration; using System. collections; using System. web; using System. web. security; using System. web. UI; using System. web. UI. webControls; using System. web. UI. webControls. webParts; using System. web. UI. htmlControls; public partial class Template: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {// declare TemplateField customFie
In the gridview, I usually adopt two methods to bind the property after the data source is bound.
One is boundfield. You only need to set the corresponding attribute name of datafield;
For example:
Another is templatefield, which is used to process special displays;
For example:
However, some events bound to rowdatabound often fail to obtain the text value in
When the gridview control is not added to a template, it is easy to get the value of a row or column.
For example:
E. Row. cells [3]. Text // gets the content in the fourth unit of the currently selected row. Here I put this line of code in the onrowdatabound event handler.
However, if templatefield is added to this column, as follows:
Width = "85px">
At this time, if you use the previous method to obtain
ASP. the gridview control in net2.0 is really strange. I don't know how Ms considers it. In the gridview, the row index is placed in the commandargument, instead of using this as the DataGrid. mydatagrid. datakeys [E. item. itemindex]. tostring () to conveniently retrieve the primary key value,
We also noticed that if the default commandfield is used,
You can use the following in rowcommand:
Code Retrieve
An important column type in the gridview control is templatefield. It can use the template to completely customize the column content. Templatefield provides six different templates for customizing the specified area of the column, or creating the mode in which the cell in the column can enter, such as the editing mode. These templates are listed in table 7-6.
different data? Or, what if we need to use a Web control other than the checkbox, Image, Hyperlink, and button to display the data? In addition, BoundField can only display a single data field. What if we want to display the values of two or more data fields in a GridView column?
To accommodate such a complex situation, the GridView provides a templatefield for
fine, but it does not support batch editing. To implement a batch of edits to the GridView, We have to make each row appear as an editing interface. The easiest way to do this is to convert the column you want to edit to TemplateField, and then create an editing interface in the ItemTemplate template. In the next few steps, we will create a full batch of editable GridV
The nested gridview displays all child records at the same time for the selected parent record organization. For example, you can use it to create a complete list of products organized by category. The next example shows how to display a complete group product list in a single grid, as shown in:
The basic technique used is to create a gridview for the appendix, and each row of it is embedded with a
Asp.net| Control
The GridView control is one of a series of data display controls that can be bound to the SqlDataSource control to dynamically generate a grid for the fields of the data records returned, and the GridView provides us with a variety of data-bound column types, such as BoundField The default data-bound column type is a simple data type that exhibits text data values.Other types of data displa
IntroductionIn the first part, you learned how to dynamically create BoundField and CommandField. However, the columns you construct often do not meet the requirements, so you need to use TemplateField. For example, if you want to create a product directory, you can certainly use a standard layout, but this is not appropriate if you want each record to have a highly customized format. In this case, you can manually modify the format of
In the circle of friends have children's shoes to me to discuss the problem of the GridView, a friend said you use the GridView to remove my table header link? I think for a long time, with the GridView is really not easy to achieve. Friends with different opinions welcome the message. However, this GridView has a yarn
Original address: http://www.dotnetbips.com/articles/displayarticledetails.aspx? Articleid = 521
[Source code download]
[Download the source code after the translator changes it]
[Translation] dynamically create a column in the GridView (Part 2)
Original article released on: 2006.11.24Author: Bipin JoshiTranslation: webabcd
IntroductionIn the first part, you learned how to dynamically create BoundField and CommandField. However, the columns you const
The display of the GridView is incomplete. -- The GridView removes the scroll bar and the gridview -- gridview
The reason that the display of the GridView is incomplete is that a sliding control is applied to its outer layer. The solution is to override the
· Use loadtemplate () method· Create a custom template Column
Use loadtemplate () to add templatefieldTo implement this example, you need to create a websit in visutal studio. Drag a gridview and sqldatasource to the detail page. We will encode some column attributes of these controls. First, we will use the loadtemplate () method to add a templatefield. The loadtemplate () method is available for all tem
-10%" buttons
Note: The GridView (and DetailsView) can also add buttons,linkbuttons or Imagebuttons to templatefields. Like BoundField, When the button is clicked, a postback is generated, triggering the Rowcommand event of the GridView. When the button is added to the TemplateField, the button's commandargument does not want to use Buttonfields, is automatica
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.